package com.mid;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by Lxk on 2020/2/18.
 */
interface NestedInteger {

    // @return true if this NestedInteger holds a single integer, rather than a nested list.
    public boolean isInteger();

    // @return the single integer that this NestedInteger holds, if it holds a single integer
    // Return null if this NestedInteger holds a nested list
    public Integer getInteger();

    // @return the nested list that this NestedInteger holds, if it holds a nested list
    // Return null if this NestedInteger holds a single integer
    public List<NestedInteger> getList();
}


class NestedIterator implements Iterator<Integer> {

    /**
     * 存放数据的容器
     */
    private List<Integer> numList = new ArrayList<>();

    /**
     * 迭代器指针
     */
    private int pointor;

    public NestedIterator(List<NestedInteger> nestedList) {
        this.pointor = 0;
        for (int i = 0; i < nestedList.size(); i++) {
            fillList(nestedList.get(i));
        }
    }

    private void fillList(NestedInteger nestedInteger) {
        if (nestedInteger.isInteger()) {
            numList.add(nestedInteger.getInteger());
        } else {
            List<NestedInteger> nestedIntegerList = nestedInteger.getList();
            for (int i = 0; i < nestedIntegerList.size(); i++) {
                fillList(nestedIntegerList.get(i));
            }
        }
    }

    @Override
    public Integer next() {
        if (this.pointor >= numList.size()) {
            return -1;
        }
        return numList.get(this.pointor++);
    }

    @Override
    public boolean hasNext() {
        return this.pointor < this.numList.size();
    }
}


public class Solution341 {

}
